﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HF.Architecture.Data;
using HF.Framework;
using HF.Framework.DataClientDBAgent;
using HF.Permission.Data;
using HF.Business.OA;

public partial class ModulePages_Address_NotepadList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //GridviewControl.ResetGridView(gvNotepadlist);
            BindData();
        }
    }

    protected void lbtDetails_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.open('NotepadListAdd.aspx?state=新建','_blank')</script>");
    }

    public void BuildNoRecords(GridView gridView, DataTable dt)
    {
        try
        {
            if (dt.Rows.Count == 0)
            {
                dt.Rows.Add(dt.NewRow());
                gridView.DataSource = dt;
                gridView.DataBind();
                int columnCount = gridView.Rows[0].Cells.Count;
                gridView.Rows[0].Cells.Clear();
                gridView.Rows[0].Cells.Add(new TableCell());
                gridView.Rows[0].Cells[0].ColumnSpan = columnCount;
                gridView.Rows[0].Cells[0].Text = "没有数据.";
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public void BindData()
    {
        DataTable userTb = OA_NOTEPAD.GetOA_NOTEPADByUserId(User.Identity.Name,20);
        gvNotepadlist.DataSource = userTb;
        gvNotepadlist.DataBind();
        BuildNoRecords(gvNotepadlist, userTb);
    }
    
    protected void gvNotepadlist_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id = gvNotepadlist.DataKeys[e.RowIndex].Value.ToString();
        OA_NOTEPAD no = new OA_NOTEPAD();
        no.Delete(id);
        Response.Redirect(Request.RawUrl);//刷新页面
       
    }
    protected void gvNotepadlist_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvNotepadlist.PageIndex = e.NewPageIndex;
        BindData();
    }
}
